﻿using System;
using spaar.ModLoader;
using UnityEngine;
using System.Reflection;

namespace LiftIndicatorMOD
{

    // If you need documentation about any of these values or the mod loader
    // in general, take a look at https://spaar.github.io/besiege-modloader.

    public class LiftIndicatorMod : Mod
    {
        public override string Name { get; } = "LiftIndicatorMod";
        public override string DisplayName { get; } = "Lift Indicator Mod";
        public override string Author { get; } = "XultimateX";
        public override Version Version { get; } = Assembly.GetExecutingAssembly().GetName().Version;

        // You don't need to override this, if you leavie it out it will default
        // to an empty string.
        public override string VersionExtra { get; } = "";

        // You don't need to override this, if you leave it out it will default
        // to the current version.
        public override string BesiegeVersion { get; } = "v0.45a";

        // You don't need to override this, if you leave it out it will default
        // to false.
        public override bool CanBeUnloaded { get; } = true;

        // You don't need to override this, if you leave it out it will default
        // to false.
        public override bool Preload { get; } = false;

        public GameObject mod;

        public static bool ModEnabled;
        public static SettingsButton ModEnabledButton;

        public override void OnLoad()
        {
            // Your initialization code here
            mod = new GameObject("LiftIndicatorMod");
            UnityEngine.Object.DontDestroyOnLoad(mod);         
            mod.AddComponent<LiftIndicatorModScript>();
            GameObject gui = new GameObject("SettingWindow");
            gui.transform.SetParent(mod.transform);
            gui.AddComponent<SettingWindow>();

            ModEnabledButton = new SettingsButton
            {
                OnToggle = (bool value)=> { ModEnabled = value;LiftBlockScript.SetAllEnable(value);LiftIndicatorModScript.SetAllEnable(value); },
                Text = "Lift",
                Value = ModEnabled = Configuration.GetBool("enabled", true),
                FontSize = 12
            };
            ModEnabledButton.Create();

        }

        public override void OnUnload()
        {
            // Your code here
            // e.g. save configuration, destroy your objects if CanBeUnloaded is true etc

            ModEnabledButton.Destroy();
            Configuration.SetBool("enabled", ModEnabled);
            Configuration.Save();

            //GameObject.Destroy(LiftIndicatorModScript.liftIndicator);
            GameObject.Destroy(mod.GetComponent<LiftIndicatorModScript>());      
            GameObject.Destroy(mod);

        }     

    }
}
